/*
 * @Author: 码上talk|RC
 * @Date: 2020-11-03 09:06:03
 * @LastEditTime: 2021-01-06 16:09:56
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /tacomall-merchant/src/model/order/index.js
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
 */
import api from '@/api'
export class Order {
    constructor(order = {}) {
        const { id, totalAmount, createTime, member } = order
        this.id = id
        this.amount = totalAmount
        this.createTime = createTime
        this.member = member
    }
}

Order.ENUM = {
    init: () => {
        return {
            orderStatus: []
        }
    },
    load: async () => {
        let result = {}
        for (let i in Order.ENUM.init()) {
            let body = {}
            const res = await api.open.enumLst({ key: i }, body)
            let { status, data } = res
            if (status) {
                result[i] = data.map(j => {
                    let json = {
                        value: j['id'],
                        label: j['name']
                    }
                    return json
                })
            }
        }
        return result
    }
}

Order.API = (type = 'list', req) => {
    switch (type) {
        case 'list':
            return new Promise((resolve) => {
                api.order.list(req.params, req.data).then(res => {
                    const { status, data, page } = res
                    if (status) {
                        resolve({ data, page })
                    }
                })
            })
        case 'info':
            return new Promise((resolve) => {
                api.order.info(req.params, req.data).then(res => {
                    const { status, data } = res
                    if (status) {
                        resolve({ data })
                    }
                })
            })
        default:
            break
    }
}